package com.bojx.report.validation;
import java.util.ArrayList;
import java.util.List;

import com.bojx.report.pojo.Result;
import com.jfinal.core.Controller;
import com.jfinal.render.JsonRender;
import com.jfinal.validate.Validator;

public class QuarterStatisValidation extends Validator {

	@Override
	protected void validate(Controller c) {
		validateInteger("year", "yearMsg", "请选择年份！");
		validateInteger("quarter", "quarterMsg","请选择季度！");
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected void handleError(Controller c) {
		String yearMsg=c.getAttr("yearMsg");
		String quarterMsg=c.getAttr("quarterMsg");
		List<String> errors=new ArrayList<>();
		if(yearMsg!=null){
			errors.add(yearMsg);
		}
		if(quarterMsg!=null){
			errors.add(quarterMsg);
		}
		Result result=new Result();
		result.setCode("10");
		result.setMessage(errors.toString());
		c.render(new JsonRender(result).forIE());
	}

}
